package com.vanke.house.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vanke.house.mapper.HouseInfoMapper;
import com.vanke.house.model.HouseInfo;
import com.vanke.house.service.HouseInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author fangyu
 * @version v1.0.0
 * @date 2020/6/18 7:14 下午
 */
@Slf4j
@Service
public class HouseInfoServiceImpl extends ServiceImpl<HouseInfoMapper, HouseInfo> implements HouseInfoService {

    @Override
    public void add(HouseInfo houseInfo) {
        QueryWrapper<HouseInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("link", houseInfo.getLink());
        Integer result = baseMapper.selectCount(wrapper);
        if (result == 0) {
            save(houseInfo);
            log.info("insert data in mysql!");
        } else {
            log.warn("house data is exist in mysql!");
        }
    }

    @Override
    public List<HouseInfo> queryHouseList() {
        QueryWrapper<HouseInfo> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("deal_time");
        wrapper.last("limit 0, 10");
        return baseMapper.selectList(wrapper);
    }
}






